<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var s="HHTHTHH";
    function judge(s){
        var arr=s.split("");
        var num=0;
        for(var i=1;i<arr.length-1;i++){
            if(arr[i-1]!==arr[i]||arr[i+1]!==arr[i]){
                num++;
            }
        }
        return num;
    }
    var m=judge(s);
    console.log(m);
</script>
</body>
</html>